import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 加载数据
data = pd.read_csv("C:\\Users\\董柳蕙\\Downloads\\heart.csv")

# 计算所有特征与目标变量的相关性
all_correlation = data.corr()['target'][:-1]  # 排除目标变量本身

# 绘制相关性热力图
plt.figure(figsize=(10, 6))
sns.heatmap(data.corr(), annot=True, cmap='coolwarm', fmt='.2f', cbar=True, linewidths=0.5)
plt.title("所有特征与目标变量相关性热力图", fontsize=16)
plt.tight_layout()
plt.show()

# 输出所有特征与目标变量的相关性
print("所有特征与目标变量的相关性：")
print(all_correlation)
